package com.anxin.response;

import com.anxin.constant.ResultCode;
import lombok.Data;

/**
 * 统一的返回体参数
 *
 * @author anxinr
 */
@Data
public class Result<T> {
    private Integer code ;
    private String massage ;
    private T body ;

    public Result(Integer code, String massage, T body) {
        this.code = code;
        this.massage = massage;
        this.body = body;
    }

    public Result(Integer code, String massage) {
        this.code = code;
        this.massage = massage;
    }

    private Result (ResultCode resultCode){
        this.code = resultCode.getCode() ;
        this.massage = resultCode.getMassage() ;
    }

    private Result (ResultCode resultCode,T body){
        this.code = resultCode.getCode() ;
        this.massage = resultCode.getMassage() ;
        this.body = body ;
    }

    public static Result success(){
        return new Result(ResultCode.SUCCESS);
    }

    public static Result fail(){
        return new Result(ResultCode.FAIL);
    }
}
